<template>
  <div class="padding_20">
    <el-button type="primary"
               @click="handleOption('add')">发 布
    </el-button>
    <element-table class="mt-20"
                   :columns="columns"
                   :data="tableData"
                   v-loading="loading"
                   pager
                   :pageTotal="pageTotal"
                   :pageIndex="pageIndex"
                   :pageSize="pageSize"
                   @handleChangePage="handleChangePage">
      <template v-slot:option="{row}">
        <el-button type="primary"
                   @click="handleOption('edit', row)">编辑
        </el-button>
        <el-button type="info"
                   @click="handleOption('statistics', row)">考核统计
        </el-button>
        <el-button type="danger"
                   @click="handleOption('del', row)">删除
        </el-button>
      </template>
    </element-table>
    <update-dialog :dataObj="dataObj"
                   v-if="showUpdateDialog"
                   :visible.sync="showUpdateDialog"/>

    <statis-dialog :dataObj="dataObj"
                   v-if="showStatisDialog"
                   :visible.sync="showStatisDialog"/>
  </div>
</template>

<script>
import ElementTable from "../../../../base/ElementTable";
import updateDiaog from "./updateDiaog";
import statisticsDialog from "./statisticsDialog";

export default {
  name: "annunciate",
  data() {
    return {
      columns: [
        {
          label: '通知名称',
          prop: 'title',
          align: "center",
          width: 200
        }, {
          label: '通知公司',
          prop: 'companyName',
          align: "center"
        }, {
          label: '通知门店数',
          prop: 'hospitalCount',
          align: 'center',

        }, {
          label: '发布时间',
          prop: 'createTime',
          align: 'center',
          formatter: (row, cellValue) => {
            return this.formatterDate(row.createTime)
          },

        }, {
          label: '是否需要考核',
          prop: 'isAssess',
          align: 'center',
          formatter:(row,cellValue)=>{
            return row.isAssess==1?'是':'否'
          }

        }, {
          label: '考核奖励(元)',
          prop: 'assessFinishAward',
          align: 'center',

        }, {
          label: '操作',
          prop: 'option',
          align: 'center',
          isSlot: true,
          width: 300
        }
      ],
      tableData: [],
      loading: false,
      pageTotal: 0,
      pageIndex: 1,
      pageSize: 20,
      dataObj: {},
      showUpdateDialog: false,
      showStatisDialog: false,

    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList(){
      this.loading = true
      this.post(this.api.promote.getManagementNoticeList, {
        pageSize: this.pageSize,
        pageIndex: this.pageIndex - 1,
      }).then((res) => {
        this.loading = false
        if (res.data.code === '200') {
          this.tableData = res.data.object
          this.pageTotal = res.data.totalNum;
        }
      })
    },
     handleOption(op, row) {
      switch (op) {
        case 'add':
          this.showUpdateDialog = true;
          this.dataObj = {}
          break;
        case 'edit':
          this.showUpdateDialog = true;
          this.dataObj = {id: row.id}
          break;
        case 'statistics':
          this.showStatisDialog = true;
          this.dataObj = {id: row.id}
          break;
        case 'del':
          this.$confirm('是否要确认?', '提示', {
            type: 'warning'
          }).then(() => {
            this.post(this.api.promote.deleteManagementNotice, {
              id:row.id
            }).then((res) => {
              if (res.data.code === '200') {
                this.$message.success('删除成功')
                this.getList()
              }
            })
          })
          break;
      }
    },
    // 分页
    handleChangePage(page) {
      this.pageIndex = page;
      this.getList();
    },
    // 时间转换
    formatterDate(time) {
      if (time)
        return this.commonFunction.timestampFormat(new Date(time), 'yyyy-MM-dd hh:mm')
      else
        return ''
    },
  },
  components: {
    'element-table': ElementTable,
    'update-dialog': updateDiaog,
    'statis-dialog':statisticsDialog
  }
}
</script>

<style scoped>

</style>
